package com.oversea.action.admissionfator;

import java.util.List;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import com.oversea.action.BaseAction;
import com.oversea.annotation.Permission;
import com.oversea.models.Admissionfator;
import com.oversea.models.School;
import com.oversea.service.AdmissionfatorService;
import com.oversea.service.SchoolService;
import com.oversea.util.page.Page;
import com.oversea.util.page.PageUtil;
import com.oversea.util.searchcontext.SearchContext;
import com.oversea.util.searchcontext.SearchOption;

@ParentPackage("oversea-default")
@InterceptorRefs( { @InterceptorRef("defaultStack") })
@Namespace("/admissionfator")
@Permission(level = 3)
public class AdmissionfatorAction extends BaseAction {

	private static final long serialVersionUID = -8199478948374178740L;

	private SchoolService schoolService;

	private AdmissionfatorService admissionfatorService;

	private List<School> schoolList;

	private List<Admissionfator> admissionfatorList;

	private School school;

	private Admissionfator admissionfator;

	private Page page;

	private int objId;

	private int gpa ; // 1很重要   2重要   3考虑    4不考虑
	private int raning ; // 1很重要   2重要   3考虑    4不考虑
	private int recommendationLetter ; // 1很重要   2重要   3考虑    4不考虑

	@SuppressWarnings("unchecked")
	public Class getActionClass() {
		return Admissionfator.class;
	}

	private SearchContext getListSearchContext() {
		SearchContext searchContext = new SearchContext();
		if (gpa > 0) {
			searchContext.addOption(new SearchOption("gpa", gpa,
					SearchOption.Option.eqaul));
		}
		if (raning > 0) {
			searchContext.addOption(new SearchOption("raning", raning,
					SearchOption.Option.eqaul));
		}
		if (recommendationLetter > 0) {
			searchContext.addOption(new SearchOption("recommendationLetter", recommendationLetter,
					SearchOption.Option.eqaul));
		}
		searchContext.setSearchClass(getActionClass());
		return searchContext;
	}


	@Action(value = "toview", results = { @Result(name = "success", type = "freemarker", location = "/WEB-INF/content/admissionfator/admissionfator_view.ftl") })
	public String view() {
		admissionfator = admissionfatorService.getObjById(objId);
		return SUCCESS;
	}

	@Action(value = "list", results = { @Result(name = "success", type = "freemarker", location = "/WEB-INF/content/admissionfator/admissionfator_list.ftl") })
	public String list() {
		page = PageUtil.createPage(pageSize, currentPage, admissionfatorService
				.getObjectCount(getListSearchContext()).intValue());
		admissionfatorList = admissionfatorService.getObjectList(getListSearchContext(),
				pageSize, currentPage);
		return SUCCESS;
	}

	public SchoolService getSchoolService() {
		return schoolService;
	}

	public void setSchoolService(SchoolService schoolService) {
		this.schoolService = schoolService;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public int getObjId() {
		return objId;
	}

	public void setObjId(int objId) {
		this.objId = objId;
	}

	public School getSchool() {
		return school;
	}

	public void setSchool(School school) {
		this.school = school;
	}

	public List<School> getSchoolList() {
		return schoolList;
	}

	public void setSchoolList(List<School> schoolList) {
		this.schoolList = schoolList;
	}

	public AdmissionfatorService getAdmissionfatorService() {
		return admissionfatorService;
	}

	public void setAdmissionfatorService(
			AdmissionfatorService admissionfatorService) {
		this.admissionfatorService = admissionfatorService;
	}

	public List<Admissionfator> getAdmissionfatorList() {
		return admissionfatorList;
	}

	public void setAdmissionfatorList(List<Admissionfator> admissionfatorList) {
		this.admissionfatorList = admissionfatorList;
	}

	public Admissionfator getAdmissionfator() {
		return admissionfator;
	}

	public void setAdmissionfator(Admissionfator admissionfator) {
		this.admissionfator = admissionfator;
	}

	public int getGpa() {
		return gpa;
	}

	public void setGpa(int gpa) {
		this.gpa = gpa;
	}

	public int getRaning() {
		return raning;
	}

	public void setRaning(int raning) {
		this.raning = raning;
	}

	public int getRecommendationLetter() {
		return recommendationLetter;
	}

	public void setRecommendationLetter(int recommendationLetter) {
		this.recommendationLetter = recommendationLetter;
	}

}
